package ccpv;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;

import repast.simphony.gis.*;
import repast.simphony.space.gis.Geography;
import repast.simphony.util.ContextUtils;
import repast.simphony.context.Context;
import repast.simphony.engine.schedule.ScheduledMethod;

public class GisAgent {
	int someData;
	private String name;
	private int age;
	private int violence;
	// for the mockup, this will be the radius of violence
	private static double radius = 0;
	private static Coordinate center = new Coordinate(58.994, 6.011);
	private static int agentCount = 239;
	private static int doneCount = 0;

	public GisAgent() {
		someData = 0;
	}

	public int getSomeData() {
		return someData;
	}

	public void setSomeData(int someData) {
		this.someData = someData;
	}
	
	  public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getViolence() {
		return violence;
	}

	public void setViolence(int violence) {
		this.violence = violence;
	}

	public double calcDist(Coordinate a, Coordinate b) {
		return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
	}

	@ScheduledMethod(start = 1, interval = 1, priority = 0)
	public void step() {
		System.out.println(name + " has called step method");
	    Context context = ContextUtils.getContext(this);
	    Geography<GisAgent> geography = (Geography)context.getProjection("Geography");
	    Geometry geom = geography.getGeometry(this);
	    Coordinate coord = geom.getCoordinates()[0];
	    if ((calcDist(coord, center) <= radius) && violence < 12)
	    	violence++;
	    
	    if (doneCount <= agentCount)
	    	doneCount++;
	    else
	    	doneCount = 0;
	    
	    if (doneCount == 0)
	    	radius+=100;
	}
}
